import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;

public class DataParseAction extends AbstractAction {

	private static final long serialVersionUID = 1L;
	String file;
	String text;


	@Override
	public void actionPerformed(ActionEvent arg0) {
		file = Window.inputField.getText();
		text = Window.inputField2.getText();
		Window.outputField.setText("");
		Thread t = new Thread(new Print(file));
		t.start();

	}
	private class Print implements Runnable{

		String file;

		Print(String file){
			this.file = file;
		}

		@Override
		public void run() {
			print(file, "");			
		}

		private void print(String f, String s){
			String indention = s;
			File file = new File(f);
			File[] dirs = file.listFiles(new FilterDirectory());
			File[] files = file.listFiles(new WordFileFilter(text));
			for(File el:files){
				Window.outputField.append(el.toString() + "\n");
			}
			for(File el:dirs){
				print(el.toString(), indention + " ");
			}
		}


	}


}
